package cn.bdqn.controller;

import cn.bdqn.utils.RedisUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/news")
public class NewsController {
    @Resource
    private RedisUtil redisUtil;
    @PostMapping("/put")
    public String put(String key,String value){
        redisUtil.putValue(key, value);
        return "success";
    }
    @PostMapping("/put2")
    public String put2(String key,String value){
        redisUtil.putValueTimeout(key, value,30);
        return "success";
    }
    @PostMapping("/resetExpire")
    public String resetExpire(String key){
        redisUtil.resetExpire(key,60);
        return "resetExpire success";
    }
    @GetMapping("/get/{key}")
    public String get(@PathVariable String key){
        return redisUtil.get(key);
    }

    @PostMapping("/multi")
    public String putMulti(String key,String value){
        Map<String,String> map=new HashMap<>();
        map.put(key,value);
        map.put("msg","success");
        redisUtil.multiPut(map);
        return "multi success";
    }
    @GetMapping("map")
    public String savemap(){
        Map<String,String>map=new HashMap<>();
        map.put("kgc","课工场");
        map.put("bdqn","愁死人了");
        redisUtil.saveMap("qn",map);
        return "map success";
    }
    @GetMapping("getmap")
    public Map<Object, Object> getmap(String key){
        return redisUtil.getMap(key);
    }
}
